<template>
<uni-shadow-root class="partials-newsList-newsList"><block v-if="receiveData.androidTemplate == ''&&receiveData.jsonData">
    
    <block v-if="receiveData.relateBean.length >= '1'">
        <view class="newListDataContainer">
          <view v-for="(item,index) in (receiveData.relateBean)" :key="item.id" class="newListDataItem" v-if="index<receiveData.jsonData.count" :data-id="item.id" :data-url="item.linkUrl" @click="tolinkUrl">
            <view v-if="item.imagePath" class="newListDataItemImage">
                <image class="new_item_icon" mode="aspectFill" :src="(item.imagePath)+'?x-oss-process=style/preview'"></image>
            </view>
            <view class="newListDataItemWord"> 
              <text class="lineheight_title font_1">{{item.title}}</text>
              <text class="word2 font_08">{{item.description}} </text> 
            </view>
          </view>
        </view>
    </block>
    <block v-if="receiveData.relateBean.length==0">
        <view class="new_noproduct">
          <image mode="widthFix" src="https://image1.sansancloud.com/xianhua/2019_12/16/15/54/55_950.jpg?x-oss-process=style/preview_120"></image>
          <text>没有相关新闻</text>
        </view>
    </block>
</block>

<block v-if="receiveData.androidTemplate == 'news_list_slide'&&receiveData.jsonData">
    
    <block v-if="receiveData.relateBean.length!=0">
      <scroll-view class="news_slide_scroll_x_box" scroll-x="true">
        <block v-for="(item,index) in (receiveData.relateBean)" :key="item.id">
          <view class="news_slide_item" :style="'background-color:'+(color)+';'" @click="tolinkUrl" :data-url="item.linkUrl" :data-id="item.id">
            <view class="news_slide_item_img">   <image mode="aspectFill" :src="item.imagePath"></image> </view>
            <view class="news_slide_item_title">{{item.title}}</view>
          </view>
        </block> 
      </scroll-view>
    </block>
    <block v-if="receiveData.relateBean.length==0">
        <view class="new_noproduct">
          <image mode="widthFix" src="https://image1.sansancloud.com/xianhua/2019_12/16/15/54/55_950.jpg?x-oss-process=style/preview_120"></image>
          <text>没有相关新闻</text>
        </view>
    </block>
</block>

<block v-if="receiveData.androidTemplate == 'common_news_list'&&receiveData.jsonData">
    
    <block v-if="receiveData.relateBean.length >= '1'">
         <view class="commonNewslist">
            <view v-for="(item,index) in (receiveData.relateBean)" :key="item.id" class="commonNewsItem" v-if="index<receiveData.jsonData.count" :data-id="item.id" :data-url="item.linkUrl" @click="tolinkUrl">
            <view v-if="item.imagePath" class="commonNewsImgBlock">
                <image mode="aspectFit" class="new_item_icon" :src="(item.imagePath)+'?x-oss-process=style/preview'"></image>
            </view> 
              <view class="ListDataItemWord"> 
              <text class="lineheight_title font_1">{{item.title}}</text>
              <text class="word2 font_08">{{item.description}} </text> 
            </view>
          </view>
        </view>
      </block>
    <block v-if="receiveData.relateBean.length==0">
        <view class="new_noproduct">
          <image mode="widthFix" src="https://image1.sansancloud.com/xianhua/2019_12/16/15/54/55_950.jpg?x-oss-process=style/preview_120"></image>
          <text>没有相关新闻</text>
        </view>
    </block>
</block>

<block v-if="receiveData.androidTemplate == 'gongyi_news_list_page'&&receiveData.jsonData">
    
    <view class="i_news_list">
        <view class="i_news_list_icon">
            <image class="i_news_list_img" mode="aspectFit" :src="receiveData.jsonData.newsIcon?receiveData.jsonData.newsIcon:'https://image1.sansancloud.com/xianhua/2019_12/30/10/36/10_16.jpg?x-oss-process=style/preview_120'"></image>
        </view> 
        <block v-if="receiveData.relateBean.length >= 1">
            <swiper :indicator-dots="false" class="i_news_swiper" display-multiple-items="2" autoplay="true" interval="5000" duration="500" vertical="true">
                <swiper-item v-for="(item,index) in (receiveData.relateBean)" :key="item.id" class="i_news_item" v-if="index<receiveData.jsonData.count" :data-url="item.linkUrl" :data-id="item.id" @click="tolinkUrl">
                    <view class="i_news_content">{{item.description}}</view>
                </swiper-item>
            </swiper>
        </block>
        <block v-if="receiveData.relateBean.length==0">
            <view class="new_noproduct">
              
              <text>没有相关新闻</text>
            </view>
        </block>
    </view>
</block></uni-shadow-root>
</template>

<script>

global['__wxRoute'] = 'partials/newsList/newsList'
const app = getApp();
Component({
  properties: {
    receiveData: {
      type: JSON,
      value: 'default value',
    }
  },
  data: {
    someData: {}
  },
  ready: function () {
      let that=this;
    // app.globalData.consoleFun("=====newsList组件-data=====",[that.data.receiveData])
    console.log("===newlsit====",that.data.receiveData)
  },
  methods: {
    tolinkUrl: function (event) {
      app.globalData.consoleFun("=====newsList组件-id=====",[event.currentTarget.dataset.id])
      let id=event.currentTarget.dataset.id;
      let url=event.currentTarget.dataset.url;
      let linkUrl='news_detail.html?id=' + id;
      if(url){
          linkUrl=url
      }
	  app.globalData.linkEvent(linkUrl)
    }
  },
})
export default global['__wxComponents']['partials/newsList/newsList']
</script>
<style platform="mp-weixin">
@import 'newsListSlide/newsListSlide.css';/* 引入可以滑动的样式 */
@import 'commonNewslist/commonNewslist.css';/* 引入可以滑动的样式 */
@import 'gongyi_news_list/index.css';/* 引入可以滑动的样式 */
/*没有相关商品  */
.new_noproduct{
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  padding: 20rpx 0;
}
.font_1{
  font-weight: bold;
}
.new_noproduct image{
  width: 150rpx;
  height: 150rpx;
  margin: 0 auto;
}
.new_noproduct text{
  font-size: 26rpx;
}
.newListDataContainer{
  display: flex;
  flex-direction: column;
  border-top: 1px solid #ddd;
  font-size: 1em;
  padding: 0.8em;
  background: #f3f3f3;
}
.newListDataItem{
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 0.8em;
  height: 4em;
  border-radius: 0.4em;
  margin-bottom: 0.8em;
  background: #fff;
}
.newListDataItemWord{
  width: 70%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: flex-start;
}
.lineheight_title{
  height:2em;
  line-height:2em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 30rpx;
  width: 100%;
}
.newListDataItemWord text{ 
  margin-left:10px;
}
.newListDataItemWord .word2 {
  font-size: 25rpx;
  color: #aaa;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
.newListDataItemImage{
  width: 30%;
  height: 100%;
  overflow: hidden;
  border-radius: 0.2em;
}
.new_item_icon{
  width: 100%;
  height: 160rpx
}
</style>